
#include <BOpenGL>
#include "member_BImage.h"

using namespace BWE;

member_BImage::member_BImage(BImage* image)
{
	boss = image;
	policy = Policy_Dynamic;
	format = Format_None;
	fmtlen = 0;
	dirty = false;
}
member_BImage::~member_BImage()
{

}

void member_BImage::resizePixels()
{
	int count = size.width() * size.height();
	if (count > 0)
	{
		int pixelSize = 0;
		switch (format)
		{
		case Format_Alpha:
		case Format_Gray:
		case Format_UChar:
			pixelSize = count;
			break;
		case Format_RGB:
			pixelSize = count * 3;
			break;
		case Format_RGBA:
		case Format_Int:
		case Format_UInt:
			pixelSize = count * 4;
			break;
		case Format_Short:
		case Format_UShort:
		case Format_Gray_Alpha:
			pixelSize = count * 2;
			break;
		case Format_Float:
			pixelSize = count * 4;
			break;
		case Format_Double:
			pixelSize = count * 8;
			break;
		default:
			break;
		}
		if (pixelSize)
		{
			if (pixels && pixels->size() == pixelSize)
				return;
			BByteArray* newPixels = new BByteArray(pixelSize);
			boss->setPixels(newPixels);
		}
		else
		{
			boss->setPixels((BByteArray*)0);
		}
	}
}